﻿// See https://aka.ms/new-console-template for more information
using Flurl.Http;
using NPOI.OpenXmlFormats.Dml;
using System.Data;

Console.WriteLine("Hello, World!");

var dt = KYSharpCore.NPOI.Excel.ExcelToDataTable(@"D:\黄明辉\项目\测试\批量成果评价\批量成果评价\files\713.xlsx", "", 0, false);

string tenantId = "3a125f25-3b76-4d38-676b-22051c4915da";
string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIzYTEyOTI1Ny1lMjhjLThiODAtODA1Mi05YjhkMDI4NjA3MWEiLCJleHAiOjE3NTA0NDQxNzUsImlzcyI6IktLU0FBUyIsImF1ZCI6IktLU0FBUyJ9.yHrDfOsSKJjWqoaxI7D89V0d7dzhIXeSjG8_ufl8w68";

string url = "https://api-kksaas.1633.com/api/aiagent/TecAnalysis/CreateTecAnalysisMany";
int i = 0;
foreach (var item in dt.AsEnumerable())
{
    i++;
    if (i < 3)
    {
        continue;
    }
    string name = item.Field<string>("专利名称");
    string desc = item.Field<string>("专利简介");
    var data = new
    {
        TecName = name,
        TecIntro = desc,
    };
    var header = new
    {
        tenantId = tenantId,
        token = token,
        username= "3a129257-e28c-8b80-8052-9b8d0286071a"
    };

    //using(var client = new HttpClient())
    //{
    //    //请求头添加tenantId和token
    //    client.DefaultRequestHeaders.Add("tenantId", tenantId);
    //    client.DefaultRequestHeaders.Add("token", token);
    //    client.DefaultRequestHeaders.Add("username", "3a129257-e28c-8b80-8052-9b8d0286071a");

    //    StringContent stringContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(data));
    //    //发送
    //    var response = await client.PostAsync(url, stringContent);
    //    //请求体添加数据

    //    var result = await response.Content.ReadAsStringAsync();
    //    Console.WriteLine(result);
    //}

    var res = await url.WithHeaders(header).PostJsonAsync(data);
    if (res.StatusCode == 200)
    {
        string str = await res.ResponseMessage.Content.ReadAsStringAsync();
        Console.WriteLine(str);
        Console.WriteLine($"第{i}条数据插入成功");
    }
    else
    {
        Console.WriteLine($"第{i}条数据插入失败");
    }
   

}
